package cn.gailvlun.gll.presentation.wish

import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProvider
import cn.gailvlun.gll.presentation.wish.maker.MakeWishViewModel


class ViewModelFactory private constructor(
) : ViewModelProvider.NewInstanceFactory() {
    companion object {
        private var sInstance: ViewModelFactory? = null
        fun getInstance(): ViewModelFactory? {
            if (sInstance == null) {
                synchronized(ViewModelFactory::class.java) {
                    if (sInstance == null) {
                        sInstance = ViewModelFactory()
                    }
                }
            }
            return sInstance
        }
    }

    override fun <T : ViewModel?> create(modelClass: Class<T>): T {
        when {
            modelClass.isAssignableFrom(MakeWishViewModel::class.java) -> {
                return MakeWishViewModel() as T
            }
            else -> throw IllegalArgumentException("unknown ViewModel class:${modelClass.name}")
        }
    }
}